package com.example.jopewars;

import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class StatusPanel extends JPanel implements GameStateChangedListener {

	private static final long serialVersionUID = 1L;
	private JTextField textFieldCash;
	private JTextField textFieldDebt;
	private JTextField textFieldBank;
	private JTextField textFieldHealth;
	private JTextField textFieldInventory;
	private JTextField textFieldBitches;
	private JTextField textFieldGuns;
	private JTextField textFieldTurnNumber;

	private GameEngine game;

	public StatusPanel() {
		game = GameEngine.getInstance();
		initialize();
	}

	private void initialize() {
		setBorder(new TitledBorder(null, "Status", TitledBorder.LEADING,
				TitledBorder.TOP, null, null));
		setLayout(new GridLayout(4, 4, 2, 2));

		JLabel lblCash = new JLabel("Cash");
		add(lblCash);

		textFieldCash = new JTextField();
		textFieldCash.setEditable(false);
		add(textFieldCash);
		textFieldCash.setColumns(10);

		JLabel lblBank = new JLabel("Bank");
		add(lblBank);

		textFieldBank = new JTextField();
		textFieldBank.setEditable(false);
		add(textFieldBank);
		textFieldBank.setColumns(10);

		JLabel lblDebt = new JLabel("Debt");
		add(lblDebt);

		textFieldDebt = new JTextField();
		textFieldDebt.setEditable(false);
		add(textFieldDebt);
		textFieldDebt.setColumns(10);

		JLabel lblHealth = new JLabel("Health");
		add(lblHealth);

		textFieldHealth = new JTextField();
		textFieldHealth.setEditable(false);
		add(textFieldHealth);
		textFieldHealth.setColumns(10);

		JLabel labelInventory = new JLabel("Inventory");
		add(labelInventory);

		textFieldInventory = new JTextField();
		textFieldInventory.setEditable(false);
		textFieldInventory.setColumns(10);
		add(textFieldInventory);

		JLabel labelBitches = new JLabel("Bitches");
		add(labelBitches);

		textFieldBitches = new JTextField();
		textFieldBitches.setEditable(false);
		textFieldBitches.setColumns(10);
		add(textFieldBitches);

		JLabel lblGuns = new JLabel("Guns");
		add(lblGuns);

		textFieldGuns = new JTextField();
		textFieldGuns.setEditable(false);
		textFieldGuns.setColumns(10);
		add(textFieldGuns);

		JLabel lblTurnNumber = new JLabel("Turn Number");
		add(lblTurnNumber);

		textFieldTurnNumber = new JTextField();
		textFieldTurnNumber.setEditable(false);
		textFieldTurnNumber.setColumns(10);
		add(textFieldTurnNumber);

		updateFields();
	}

	public void updateFields() {
		textFieldCash.setText(Long.toString(game.getCashAmount()));
		textFieldDebt.setText(Long.toString(game.getDebtAmount()));
		textFieldBank.setText(Long.toString(game.getBankAmount()));
		textFieldHealth.setText(Integer.toString(game.getHealthAmount()));
		textFieldGuns.setText(Integer.toString(game.getNumberOfGuns()));
		textFieldBitches.setText(Integer.toString(game.getNumberOfBitches()));
		textFieldInventory.setText(Integer.toString(game.getSpaceAvailable()));
		textFieldTurnNumber.setText(Integer.toString(game.getTurnNumber()));
	}

	@Override
	public void gameStateChanged() {
		updateFields();
	}

}
